#pragma once

#include <osgGA/GUIEventHandler>
#include <osg/Quat>
#include <osg/AnimationPath>
#include <osgViewer/Viewer>
#include <osg/Material>
#include <osgGA/MatrixManipulator>

using namespace osgGA;

class GizmoManipulator : public osgGA::GUIEventHandler
{
  public:
       GizmoManipulator();
      ~GizmoManipulator();

      bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa);
      osg::MatrixTransform* pickTransform(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter& ea);
      void mouse_down();
      void mouse_move();
      void mouse_up();
      void select(osg::MatrixTransform* t);
  
  protected:
    enum ACTION { NOP, TRANSLATE, ROTATE, SCALE };
    enum AXIS   { X, Y, Z, NONE };

    ACTION _action;
    AXIS   _axis;
    osg::ref_ptr<osg::MatrixTransform> _sel;
    osg::ref_ptr<osg::MatrixTransform> _gizmo;
    osg::ref_ptr<osg::MatrixTransform> _gizmo_axis[3];
    osg::ref_ptr<osg::Material>        _axis_material[3];

    osg::ref_ptr<osgGA::MatrixManipulator> _camera_manip;
};
